﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProcessFile
{
   public class ConvertAD144Stk
    {
        public static string ConvertFilesAd144Stk(string filePath)
        {

            AD14File content = new AD14File(filePath);
            string[] layerItems = content.LayerItems;
            string convertConent = "";
            int layerNo = 0;
            for (int i = 1; i < layerItems.Length - 1; i++)
            {

                ConvertAD144StkRow ad144StkRow = new ConvertAD144StkRow(layerItems[i]);
                if (!ad144StkRow.IsDielectric)
                {
                    layerNo++;
                    ad144StkRow.LayerNo = layerNo;
                }
               
                if (i == 1)
                {
                    ad144StkRow.IsTopSolder = true;
                }
                if (i == layerItems.Length - 2)
                {
                    ad144StkRow.IsBottomSolder = true;
                }
                convertConent+=ad144StkRow.ToString()+'\n';
            }
            convertConent +=content.Unit;
            return convertConent;
        }
        public static string[] ConvertFilesAd144StkStage2(string filePath, ref List<SubStackItem> subStack )
        {

            AD14File content = new AD14File(filePath);
            string[] layerItems = content.LayerItems;
          subStack = content.SubStackItemContent;
            string[] convertConent = new string[subStack.Count];
            int layerNo = 0;
            for (int i = 1; i < layerItems.Length - 1; i++)
            {

                ConvertAD144StkRow ad144StkRow = new ConvertAD144StkRow(layerItems[i]);
                if (!ad144StkRow.IsDielectric)
                {
                    layerNo++;
                    ad144StkRow.LayerNo = layerNo;
                }

                if (i == 1)
                {
                    ad144StkRow.IsTopSolder = true;
                }
                if (i == layerItems.Length - 2)
                {
                    ad144StkRow.IsBottomSolder = true;
                }
                for (int j = 0; j < subStack.Count; j++)
                {
                    if (ad144StkRow.GetOnOf(subStack[j].SubStackId) == "0")
                    {
                        convertConent[j] += ad144StkRow.ToString() + '\n';
                    }
                }
              
                   

               
            }
            for (int i = 0; i < convertConent.Length; i++)
            {
                convertConent[i] += content.Unit;
            }
         
            return convertConent;
        }
    }
}
